#ifndef GAME_ANIMATION_SUN_SHADER_H
#define GAME_ANIMATION_SUN_SHADER_H
//
// Game Animation.
// Copyright (C) 2007 Department of Computer Science, University of Copenhagen
//
#include <animation/configuration.h>

#include <OpenTissue/gpu/cg/cg_program.h>

namespace animation
{

  /**
  * The Sun Shader.
  * Sets up rendering before drawing terrain geometry.
  */
  class SunShader
  {

  protected:

    OpenTissue::cg::Program       m_vertex_program;
    OpenTissue::cg::Program       m_fragment_program;
  public:
	  void pre_render( bool reload    
	  ,	float rightx , float righty  , float rightz
      , float upx , float upy  , float upz
	  , float time
	  , float fog_density
	  , float fog_color_r, float fog_color_g, float fog_color_b
	  ){

		  if(!m_vertex_program.is_program_loaded()||reload)
			  m_vertex_program.load_from_file(OpenTissue::cg::Program::vertex_program,demo_path + "../animation/shader/sun/sun_vp.cg");
		  m_vertex_program.set_modelview_projection_matrix();
		  m_vertex_program.set_float_param("right",               rightx, righty, rightz);
		  m_vertex_program.set_float_param("up",                  upx,    upy,    upz);
		  
		  //--- load fragment program
		  if(!m_fragment_program.is_program_loaded()||reload)
			  m_fragment_program.load_from_file(OpenTissue::cg::Program::fragment_program,demo_path + "../animation/shader/sun/sun_fp.cg");
		 
		  m_fragment_program.set_float_param("time",time);
		  m_fragment_program.set_float_param( "fog_density",  fog_density  );
		  m_fragment_program.set_float_param( "fog_color",  fog_color_r,fog_color_g,fog_color_b);

		  m_vertex_program.enable();
		  m_fragment_program.enable();
		  glEnable(GL_BLEND);
		  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    void post_render(){
		glDisable(GL_BLEND);
		m_fragment_program.disable();
		m_vertex_program.disable();
    }

  };

} // namespace animation

// GAME_ANIMATION_TERRAIN_SHADER_H
#endif
